#include<bits/stdc++.h>
using namespace std;
#define int long long

vector<int> days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void solution1(int n) {
    auto getDate = [](int y, int m, int d) {
        string s = "";
        s += to_string(y);
        s += (m < 10 ? "0" : "") + to_string(m);
        s += (d < 10 ? "0" : "") + to_string(d);
        return s;
    };

    int y = n / 10000;
    int m = n / 100 % 100;
    int d = n % 100;

    bool flag = 0;

    for(int i = y;; i++) {

        if((i % 4 == 0 && i % 100) || (i % 400 == 0))
            days[2] = 29;
        else
            days[2] = 28;

        for(int j = 1; j <= 12; j++) {

            if(i == y && j < m)	j = m;

            for(int k = 1; k <= days[j]; k++) {

                if(i == y && j == m && k < d)	k = d + 1;

                string s = getDate(i, j, k);
                string t = s;
                reverse(t.begin(), t.end());

                if(t != s)	continue;

                if(!flag) {
                    flag = 1;
                    cout << s << endl;
                }

                if( (t[0] == s[0] && t[2] == s[2] && t[0] == t[2]) &&
                        (t[1] == s[1] && t[3] == s[3] && t[1] == t[3]) ) {
                    cout << s;
                    return;
                }
            }
        }
    }
}


void solution2(int n) {
    int y = n / 10000 - 1;
    int m, d;

    bool f1, f2;
    f1 = f2 = 0;

    while(!f1 || !f2) {
        y++;

        if((y % 4 == 0 && y % 100) || (y % 400 == 0))
            days[2] = 29;
        else
            days[2] = 28;

        string s = to_string(y);
        string t = s;
        reverse(s.begin(), s.end());

        if(t + s <= to_string(n))	continue;

        m = (s[0] - '0') * 10 + (s[1] - '0');

        if(m < 1 || m > 12)	continue;

        d = (s[2] - '0') * 10 + (s[3] - '0');

        if(d < 1 || d > days[m])	continue;

        if(!f1) {
            f1 = 1;
            cout << t + s << endl;
        }

        if(f1) {
            if(s[0] == s[2] && s[1] == s[3]) {
                cout << t + s;
                f2 = 1;
            }
        }
    }
}


signed main() {
//	system("start https://www.lanqiao.cn/problems/498/learning/");

    int n;
    cin >> n;

    solution2(n);

    return 0;
}

